SET SERVEROUTPUT ON SIZE 1000000;
SET VERIFY OFF

DECLARE
	l_total_extracted	NUMBER;
	l_total_imported	NUMBER;				
	l_func_id			VARCHAR2(100):='CAPARREC_CUSTOMER_LOCATION';
	l_code VARCHAR2(100):=UPPER('&1');

BEGIN
	SELECT COUNT(1)
	INTO l_total_extracted        
      from   hz_cust_acct_sites_all hcas,
             hz_party_sites hps,
      	     hz_locations hl,
      	     hr_organization_information hoi,
      	     GL_SETS_OF_BOOKS A 
      where  hcas.party_site_id = hps.party_site_id
      and    hps.location_id = hl.location_id
      and    hcas.org_id = hoi.organization_id
      and    hoi.org_information_context = 'Operating Unit Information' 
      and    hoi.org_information3 = to_char(A.SET_OF_BOOKS_ID)
      AND    UPPER(A.SHORT_NAME) = l_code;
	
	SELECT COUNT(1) 
	INTO l_total_imported
	FROM CRST_HZ_LOCATIONS;

	dbms_output.put_line('Function: '||l_func_id);		
	dbms_output.put_line('Total Extracted: '||TO_CHAR(l_total_extracted)) ;
	dbms_output.put_line('Total Imported:  '||TO_CHAR(l_total_imported));
	IF l_total_extracted <> l_total_imported THEN
		dbms_output.put_line('Error: No. of Records do not match!');
	END IF;		
						
EXCEPTION
	WHEN OTHERS THEN	
		dbms_output.put_line('Function Error: '||l_func_id);			
END;
/
